const path = require('path');
const {themeVars} = require('./src/shared/themeVars')
const {
	fixBabelImports
	, override
	, addWebpackPlugin
	, addLessLoader
	, addDecoratorsLegacy
	, useBabelRc
	, disableEsLint
	, addWebpackResolve
} = require('customize-cra')
// const rewireLess = require('react-app-rewire-less')
const AntDesignThemePlugin = require('antd-theme-webpack-plugin')

const options = {
	stylesDir: path.join(__dirname, './src/less'),
	antDir: path.join(__dirname, './node_modules/antd'),
	varFile: path.join(__dirname, './src/less/vars.less'),
	//包含所有自定义样式导入的文件
	mainLessFile: path.join(__dirname, './src/less/main.less'),
	themeVariables: themeVars,
	indexFileName: 'index.html',
	generateOnce: false
}


//NODE_ENV: 该变量是自动赋值的，你不可以更改它的值，对于npm start, 它的值是develepment, npm test它的值是test, 对于npm run build, 它的值是production
module.exports = override(
	disableEsLint(),
	addDecoratorsLegacy(),
	useBabelRc(),
	addWebpackResolve({
		modules: [
			path.resolve(__dirname, "node_modules"),
			path.resolve(__dirname, "src/index"),
			path.resolve(__dirname, "src/shared"),
			path.resolve(__dirname, "src/images"),
		]
	}),
	fixBabelImports('import', {
		libraryName: 'antd',
		libraryDirectory: 'es',
		style: true,
	}),
	addLessLoader({
		javascriptEnabled: true,
		modifyVars: {
			'@primary-color': '#1890ff',
			'@link-color': '#1890ff',
			'@theme': 'default'
		},
	}),
	addLessLoader({
		javascriptEnabled: true,
	}),
	addWebpackPlugin(new AntDesignThemePlugin(options))
)